package kr.hkit.androidcomplete01.chapter09;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ContextMenuEx extends Activity {
	Button mBtn;
	EditText mEdit;
	MyImage mImg;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch09_contextmenuex);
		
		mBtn = (Button) findViewById(R.id.ch09_contextmenu_btn);
		mEdit = (EditText) findViewById(R.id.ch09_contextmenu_edit);
		mImg = (MyImage) findViewById(R.id.ch09_contextmenu_myImage);
		
		registerForContextMenu(mBtn);
		registerForContextMenu(mEdit);
		registerForContextMenu(mImg);
	}
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		if (v==mBtn){
			menu.setHeaderTitle("Button Menu");
			menu.add(0, 1, 0, "Red");
			menu.add(0, 2, 0, "Green");
			menu.add(0, 3, 0, "Blue");
		}
		if (v==mEdit){
			menu.setHeaderTitle("EditText Menu");
			menu.add(0, 3, 0, "번역하기");
			menu.add(0, 4, 0, "필기인식");
		}
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		switch(item.getItemId()){
		case 1: mBtn.setTextColor(Color.RED);	return true;
		case 2: mBtn.setTextColor(Color.GREEN);	return true;
		case 3: mBtn.setTextColor(Color.BLUE);	return true;
		case 4: mEdit.setText("번역했다");		return true;
		case 5: mEdit.setText("필기인식했다");		return true;
		case 100: Toast.makeText(this, "이미지 회전", Toast.LENGTH_LONG).show(); return true;
		case 101: Toast.makeText(this, "크기 변경", Toast.LENGTH_LONG).show(); return true;
		}
		return false;
	}
}
